$(function(){

    // if (window.navigator.userAgent.indexOf("MSIE 7.0")>=1){
    //     setActiveStyleSheet("ie7.css");
    // }

    var one_text = $('.one_text p');
    var one_best_span = $('.one_best .best span');
    var tail_li = $('.tail_ul li');
    let scro = 0;
    if($(window).scrollTop() == 0){
        visual(0,one_text,"bottom",0)
        visual(0,one_best_span,"opacity",1)
        visual(0,tail_li,"left",0)
    }
    $(window).scroll(function(e){
        let llqhe = $(window).height() //浏览器可视区域高度
        let newScro = $(window).scrollTop() //滚动条滚动距离
        if(scro < newScro){
            visual(newScro,one_text,"bottom",0)
            visual(newScro,one_best_span,"opacity",1)
            visual(newScro,tail_li,"left",0)
            scro = newScro
        }else{
            visual(newScro,one_text,"bottom",0)
            visual(newScro,one_best_span,"opacity",1)
            visual(newScro,tail_li,"left",0)
            scro = newScro
        }
    })
    function visual(a,d,e,f){
        var dhe = d.outerHeight()
        var dtop = d.offset().top
        if(a < dhe+dtop){ //元素在可视区域
            switch(e){
                case "bottom":
                    d.animate({ //实现文字从下方滑上来
                        bottom: f
                    },1000)
                break;
                case "opacity":
                    d.animate({ //实现文字隐藏显示
                        opacity: f
                    },1000)
                break;
                case "left":
                    d.animate({ //实现文字从右边滑过来
                        left: f
                    },2000)
                break;
            }
        }
    }


    //设置按钮购买事件
    var gm = $('.gm')
    gm.click(function(){
        $(this).addClass("jz")
        $(this).text("已购买")
    })


    //设置弹出框隐藏显示
    var xm_img = $('.xm img')
    xm_img.click(function(){
        $(this).siblings(".tck").stop().fadeIn(1000)
        $(this).parents(".xm").siblings().find(".tck").stop().fadeOut(1000)
        console.log($(this).siblings(".tck").css("display"))
        if($(this).siblings(".tck").css("opacity") == 1){
            $(this).siblings(".tck").stop().fadeOut(1000)
        }
    })


    //移动端改变页面
    var best_img = $('.best img')
    var topimg = $('.topimg img')
    var cq_xm_img = $('.cq .xm:first img')
    var appimg = ['images/daoj/daoj4.jpg','images/daoj/daoj3.jpg','images/daoj/daoj1.jpg','images/daoj/daoj5.jpg','images/daoj/daoj6.jpg']
    var apptext = ['全赛季巨星混合包(含终极传奇) BEST100 *1','LP巨星3强BEST100(含UL1强) *1','16EC巨星3强BEST100(含UL1强) *1','1000W EP','世界级助教(1.0-5.0星 ×3)']
    if(isMobile()){
        best_img.each(function(key,val){
            $(this).attr("src",appimg[key])
            $(this).siblings("span").text(apptext[key])
        })
        topimg.attr("src","images/daoj/yd.jpg")
        cq_xm_img.attr("src","../cshi/images/daoj/daoj7.jpg")
    }
    //判断是否是手机
    function isMobile() {
        var userAgentInfo = navigator.userAgent;
        var mobileAgents = [ "Android", "iPhone", "SymbianOS", "Windows Phone", "iPad","iPod"];
        var mobile_flag = false;
        //根据userAgent判断是否是手机
        for (var v = 0; v < mobileAgents.length; v++) {
            if (userAgentInfo.indexOf(mobileAgents[v]) > 0) {
                mobile_flag = true;
                break;
            }
        }
         var screen_width = window.screen.width;
         var screen_height = window.screen.height;    
         //根据屏幕分辨率判断是否是手机
         if(screen_width < 500 && screen_height < 800){
             mobile_flag = true;
         }
         return mobile_flag;
    }
})